//转化省标数据内容
var pageii = null;
var baseURL = "../../";
$(function () {

})

var vm = new Vue({
	el: '#insertmodify',
	data: {
		id:'',
		user:{},
		userId:'',
		questionModifyData: {},
		file:'',
		filePath:[]
	},
	mounted () {
        this.getUserInfomation();
       
    },
    
    methods: {
    	beforeAvatarUpload(file) {
    		debugger;
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;
            var r = /[+/?%=&#]/;
            var isZf = true;
            if(file.name.search(r) > -1){
                layer.msg("上传图片名包含非法字符!");
                isZf = false;
            }
            
            if (!isJPG) {
            	layer.msg('上传头像图片只能是 JPG 格式!');
            }
            if (!isLt2M) {
            	layer.msg('上传头像图片大小不能超过 2MB!');
            }
            return isJPG && isLt2M && isZf;
          },

    handleRemove(file, fileList) {
                console.log(fileList)
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            handleOnSuccess(response, file, fileList){
                console.log(fileList)
                $("#fileListLength").val(fileList.length);
                for (var i = 0; i<fileList.length;i++){
                    $("#file"+(i+1)).val(fileList[i].response.filePath)
                }
            },
    	
    	changeImage: function(e) {
    	     var file = e.target.files[0];
    	     var obj = document.getElementById("avatar");
    	     $("#upfile").val(obj.files[0].name);
    	     let da = new FormData();
 	    	 da.append("file", file);
    	     $.ajax({
 	            type: "POST",
 	            data: da,
 	            url: baseURL + 'app/common/file/uploadFile',
 	            chacke: false,
 	            processData: false,  // 告诉jQuery不要去处理发送的数据
 	            contentType: false,  // 告诉jQuery不要去设置Content-Type请求头
 	            success: function (data) {
 	            	debugger;
 	                vm.filePath.push(data.filePath);
 	            }
 	    	});
        },
    	
    	getUserInfomation: function() {

    		let url = baseURL;
    		url = url + "business/supervise/getUserInfomation";
    		$.ajax({
                type: "GET",
                url: url,
                //data:params,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                    	debugger;
                        vm.user = res.userInfo;
                        vm.userId = res.userId;
                    } else {
                        alert(res.msg);
                    }
                }
            });
    	},
    	//获取文件名
        getFileName(o) {
            var pos = o.lastIndexOf("/");
            return o.substring(pos + 1);
        },
    	insertQuestionModify() {debugger
    		let recordId = $("#recordId").val();
    		let questionId = $("#questionId").val();
    		let qksm = $("#qksm").val();
    		var b = $("#fileListLength").val();
    		var SupervisionQuestionBean = new Object();
    		SupervisionQuestionBean.superviseImageEntityList = []
            if(b != 0){
                for (var a = 1; a < (b-0+1); a++ ){
                    var SuperviseImageEntity = new Object();
                    SuperviseImageEntity.picUrl = $("#file"+a).val();
                    SupervisionQuestionBean.superviseImageEntityList.push(SuperviseImageEntity);
                }
            }
            SupervisionQuestionBean.questionId = questionId;

    	    debugger;
    		let params = {
    			dcRecordId:recordId,
    			dcQuestionId: questionId,
    			zgfknr:qksm,
    			fjPath:JSON.stringify(SupervisionQuestionBean)
            }
    		let url = baseURL;
    		url = url + "business/supervisequestionmodify/insertQuestionModify";
    		$.ajax({
                type: "GET",
                url: url,
                data:params,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                    	//debugger;
                    	alert('操作成功', function(index){
                    		parent.location.reload();
						});
                    } else {
                        alert(res.msg);
                    }
                }
            });
    	},
    
    }
	

	
});

